package com.khiker.array;

import java.util.HashMap;
import java.util.Map;

public class P1_TwoSum {
	public int[] twoSum(int[] nums, int target) {
		Map<Integer, Integer> map = new HashMap<>(nums.length);
		for (int i = 0; i < nums.length; i++) {
			Integer result = map.get(target - nums[i]);
			if (result != null) {
				return new int[]{result, i};
			}
			map.put(nums[i], i);
		}
		return null;
	}

	public static void main(String[] args) {
		P1_TwoSum problem = new P1_TwoSum();
		problem.twoSum(new int[]{2, 7, 11, 15}, 9);
	}

}
